﻿using System;
using LitJson;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

namespace CGF
{
    //提前声明后，热更资源才会支持使用以下异步的泛型
    public class ReferentClasses
    {
        CTask<bool> task01 = null;
        CTask<bool[]> task02 = null;
        CTask<List<bool>> task03 = null;

        CTask<byte> task04 = null;
        CTask<byte[]> task05 = null;
        CTask<List<byte>> task06 = null;

        CTask<int> task07 = null;
        CTask<int[]> task08 = null;
        CTask<List<int>> task09 = null;

        CTask<long> task10 = null;
        CTask<long[]> task11 = null;
        CTask<List<long>> task12 = null;

        CTask<float> task13 = null;
        CTask<float[]> task14 = null;
        CTask<List<float>> task15 = null;

        CTask<double> task16 = null;
        CTask<double[]> task17 = null;
        CTask<List<double>> task18 = null;

        CTask<string> task19 = null;
        CTask<string[]> task20 = null;
        CTask<List<string>> task21 = null;

        CTask<JsonData> task22 = null;
        CTask<IntPtr> task23 = null;

        static UnityAction uAction1 = null;
        static UnityAction<bool> uAction2 = null;
        static UnityAction<int> uAction3 = null;
        static UnityAction<float> uAction4 = null;
        static UnityAction<string> uAction5 = null;
        static UnityAction<Vector2> uAction6 = null;
        static UnityAction<Vector3> uAction7 = null;

        static UnityEvent uEvent1 = null;
        static UnityEvent<bool> uEvent2 = null;
        static UnityEvent<int> uEvent3 = null;
        static UnityEvent<float> uEvent4 = null;
        static UnityEvent<string> uEvent5 = null;
        static UnityEvent<Vector2> uEvent6 = null;
        static UnityEvent<Vector3> uEvent7 = null;
        
        static Action<IntPtr> action1 = null;
        

        public static async void Init(MonoBehaviour monoBehaviour)
        {
            if (uEvent1 != null) uEvent1.AddListener(() => { });
            if (uEvent2 != null) uEvent2.AddListener((b) => { });
            if (uEvent3 != null) uEvent3.AddListener((i) => { });
            if (uEvent4 != null) uEvent4.AddListener((f) => { });
            if (uEvent5 != null) uEvent5.AddListener((s) => { });
            if (uEvent6 != null) uEvent6.AddListener((v2) => { });
            if (uEvent7 != null) uEvent7.AddListener((v3) => { });
            
            if (uEvent1 != null) uEvent1.RemoveListener(() => { });
            if (uEvent2 != null) uEvent2.RemoveListener((b) => { });
            if (uEvent3 != null) uEvent3.RemoveListener((i) => { });
            if (uEvent4 != null) uEvent4.RemoveListener((f) => { });
            if (uEvent5 != null) uEvent5.RemoveListener((s) => { });
            if (uEvent6 != null) uEvent6.RemoveListener((v2) => { });
            if (uEvent7 != null) uEvent7.RemoveListener((v3) => { });
            
            if (uEvent1 != null) uEvent1.RemoveAllListeners();
            if (uEvent2 != null) uEvent2.RemoveAllListeners();
            if (uEvent3 != null) uEvent3.RemoveAllListeners();
            if (uEvent4 != null) uEvent4.RemoveAllListeners();
            if (uEvent5 != null) uEvent5.RemoveAllListeners();
            if (uEvent6 != null) uEvent6.RemoveAllListeners();
            if (uEvent7 != null) uEvent7.RemoveAllListeners();

            await CTask.Wait(1);
            monoBehaviour.StartCoroutine(SetStatus());
        }

        static System.Collections.IEnumerator SetStatus()
        {
            yield return new WaitForSeconds(2);
            yield return new WaitForEndOfFrame();
        }
    }
}